/*
 * Created on 13.02.2009
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package org.higginsexamples.mailboxserver;

import java.util.Hashtable;

import javax.servlet.ServletException;

import org.osgi.service.component.ComponentContext;
import org.osgi.service.http.HttpContext;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;

/**
 * @deprecated
 */
public class ComponentLifecycle
{
	public ComponentLifecycle()
	{
		super();
	} // ComponentLifecycle() 

	public void initialize( HttpService httpService )
	{
		HttpContext httpContext ;
		
//		httpContext = httpService.createDefaultHttpContext();
		httpContext = new BasicSecurityHttpContext();
		this.registerResources(httpService,httpContext);
		this.registerServlets(httpService,httpContext);
	} // initialize() 

	public void cleanup( HttpService httpService )
	{
		httpService.unregister( "/index.html" ) ;
	} // cleanup() 
	
	protected void registerResources( HttpService httpService, HttpContext httpContext )
	{
		try
		{
			httpService.registerResources( "/index.html", "/html/index.html", httpContext ) ;
		}
		catch ( NamespaceException ex )
		{
			ex.printStackTrace();
		}
	} // registerResources() 
	
	protected void registerServlets( HttpService service, HttpContext httpContext ) 
	{
		try
		{
			service.registerServlet( "/mailboxes", new MailboxRetrievalServlet(), new Hashtable(), httpContext );
		}
		catch ( ServletException ex )
		{
			ex.printStackTrace();
		}
		catch ( NamespaceException ex )
		{
			ex.printStackTrace();
		}
	} // registerServlets() 

	protected void activate( ComponentContext context ) 
	{
	} // activate()
	
} // class ComponentLifecycle 
